package leetcode;

/**
 * Created with IntelliJ IDEA.
 * User: Ghost
 * Date: 14-6-10
 * Time: 下午5:01
 * To change this template use File | Settings | File Templates.
 */
public class Linked_List_Cycle {

    public boolean hasCycle(ListNode head) {
        if(head==null)
            return false;
        ListNode fast = head;
        ListNode slow = head;
        while(fast!=null){
            fast = fast.next;
            slow = slow.next;
            if(fast!=null)
                fast = fast.next;
            if(fast == slow && fast!=null)
                return true;
        }
        return false;
    }

}
